package com.cwt.common.utils;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.util.ObjectUtils;

import java.util.Map;

/**
 * @author chenwt
 * @version V1.0
 * @describe 【sql utils】
 * @date 2023年03月01日 14:33:12
 */
public class SqlUtils extends com.baomidou.mybatisplus.core.toolkit.sql.SqlUtils {

    public static String params(Map<String, Object> params) {
        StringBuilder param = new StringBuilder();
        param.append(" 1 = 1 ");
        params.forEach((key, value) -> {
            if (!ObjectUtils.isEmpty(value)) {
                param.append(" AND ").append(key).append(" = ").append("'").append(value).append("'");
            }
        });
        return param.toString();
    }

    public static void wrapperSetEqCondition(QueryWrapper queryWrapper, Map<String, Object> params) {
        params.forEach((key, value) -> {
            if (!ObjectUtils.isEmpty(value)) {
                queryWrapper.eq(key, value);
            }
        });
    }

    public static void wrapperSetLikeCondition(QueryWrapper queryWrapper, Map<String, Object> params) {
        params.forEach((key, value) -> {
            if (!ObjectUtils.isEmpty(value)) {
                queryWrapper.like(key, value);
            }
        });
    }

}
